<%--
  Created by IntelliJ IDEA.
  User: SXLWTT
  Date: 2021/10/22
  Time: 16:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="/js/jquery-1.9.1.min.js"></script>
    <script src="/js/fileupload.js"></script>
    <link rel="stylesheet" href="/css/img.css">
</head>
<body>
<form>
    <input type="hidden" name="aid" value="${param.aid}">
    文章标题：<input type="text" name="title"><br>
    文章图片：<div class="photoUpLoad" >
    <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
    <img src="" alt="" class="photoEcho">
</div><br>
    文章内容：<input type="text" name="content"><br>
    所属标签：
    <div id="div"></div>
    <input type="button" value="修改"onclick="add()">
</form>
</body>
</html>
<script>
    $.ajax({
        url:"listTag.do",
        type:"post",
        dataType:"json",
        success:function (obj) {
            for (var i in obj){
                console.log(obj[i])
                $("#div").append("<input type='checkbox' name='tids' value='"+obj[i].tid+"'>"+obj[i].tname)
            }
        }
    })
    $.ajax({
        url:"listHui.do",
        data:{aid:${param.aid}},
        type:"post",
        datType:"json",
        success:function (obj) {
            $("[name='title']").val(obj.title)
            $("[name='content']").val(obj.content)
            $(".photoEcho").prop("src",obj.pic)
            var strings = obj.tnames.split(",");
            for (var i in strings){
                $("[name='tids'][value='"+strings[i]+"']").prop("checked",true)

            }
        }
    })
    function add() {
        var formData = new FormData($("form")[0]);
        $.ajax({
            url:"update.do",
            data:formData,
            type:"post",
            dataType:"json",
            success:function (obj) {
                if (obj>0){
                    alert("修改成功")
                    location="list.do"
                }
            }, processData:false,
            contentType:false
        })
    }
</script>